package com.coders.util;

import org.cocos2d.types.CGSize;

import android.content.Context;
import android.widget.Toast;

/**
 * Collection of common utility methods.
 * 
 * @author Subin
 * 
 */
public final class CommonUtil
{
    static
    {
        basePath = "images/hdpi/";
    }

    private static String     basePath;

    private static CommonUtil commonUtil        = null;

    public static String      IMG_PATH_HIGH_RES = "images/hdpi/";
    public static String      IMG_PATH_MED_RES  = "images/mdpi/";
    public static String      IMG_PATH_LOW_RES  = "images/ldpi/";

    private CommonUtil()
    {
    }

    public static CommonUtil getInstance()
    {
        if ( null == commonUtil )
        {
            commonUtil = new CommonUtil();
        }

        return commonUtil;
    }

    public static void showToast( String message, Context context )
    {
        Toast pieceToast = Toast.makeText( context, message, Toast.LENGTH_SHORT );
        pieceToast.show();
    }

    public static void showWorkInProgressToast( Context context )
    {
        showToast( "We're working to improve this. This feature will be available in future versions of the product",
                context );
    }

    /**
     * This is to identify the image directories. cocos2d doesn't detect res
     * directory. We need to hold all images used in game in 'assets' folder.
     * Based on screen size we need to choose either assets/hdpi, assets/mdpi
     * etc
     * 
     * @param paramCGSize
     * @return
     */
    public static String getBasePath( CGSize paramCGSize )
    {

        /*
         * if ( ( paramCGSize.width <= 320.0F ) || ( paramCGSize.height <=
         * 480.0F ) ) { return "1x"; } else { return "2x"; }
         */

        // if()
        if ( ( paramCGSize.width <= 320.0F ) && ( paramCGSize.height <= 240.0F ) )
        {

            return IMG_PATH_LOW_RES;
        }
        else
        {
            return  IMG_PATH_HIGH_RES ;
        }
    }

   /* public static String getImagePath( String imageKey )
    {
        return getBasePath() + imageKey;
    }*/
  
    
    

    public static String getBasePath()
    {
        return basePath;
    }

    public static void setBasePath( String basePath )
    {
        CommonUtil.basePath = basePath;
    }

    public static String getImagePath( String imageKey, CGSize winSize )
    {
        return getBasePath(winSize) + imageKey;
    }
    

}
